package sort;

public class QuickSort {
    public static void main(String[] args) {
        int res[] = {6,1,2,7,9,3,4,5,10,7,8};
        quickSort(res, 0, res.length-1);
        for (int item : res) {
            System.out.println(item);
        }
    }

    public static void quickSort(int[] arr,int i,int j ){
        int start = i,end = j;
        if (start>end) {
            return;
        }
        int baseV = arr[i];
        while(start!=end){
            while(true){
                if(start>=end||baseV>arr[end]){
                    break;
                }
                end--;
            }
            while(true){
                if(start>=end||baseV<arr[start]){
                    break;
                } 
                start++;
            }
            int temp = arr[start];
            arr[start] =arr[end]; 
            arr[end] = temp;
        }
        int tmp = arr[start];
        arr[start] = arr[i];
        arr[i] = tmp;

        quickSort(arr, i, start-1);
        quickSort(arr, start+1, j);
    }

}
